package com.ruoyi.web.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.web.entity.Coupon;
import com.ruoyi.web.mapper.CouponMapper;
import com.ruoyi.web.service.ICouponService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lqc
 * @since 2024-01-27
 */
@Service
public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> implements ICouponService {

    private final CouponMapper couponMapper;
    public CouponServiceImpl(CouponMapper couponMapper){
        this.couponMapper = couponMapper;
    }

    @Override
    public List<Coupon> selectByCustomerId() {
        LoginUser loginUser = getLoginUser();
        SysUser user = loginUser.getUser();
        return couponMapper.selectByCustomerId(user.getUserId());
    }

    @Override
    public Coupon selectCouponById(Long id)
    {
        return couponMapper.selectCouponById(id);
    }

    /**
     * 查询优惠券管理列表
     *
     * @param coupon 优惠券管理
     * @return 优惠券管理
     */
    @Override
    public List<Coupon> selectCouponList(Coupon coupon)
    {
        return couponMapper.selectCouponList(coupon);
    }

    /**
     * 新增优惠券管理
     *
     * @param coupon 优惠券管理
     * @return 结果
     */
    @Override
    public int insertCoupon(Coupon coupon)
    {
        return couponMapper.insertCoupon(coupon);
    }

    /**
     * 修改优惠券管理
     *
     * @param coupon 优惠券管理
     * @return 结果
     */
    @Override
    public int updateCoupon(Coupon coupon)
    {
        return couponMapper.updateCoupon(coupon);
    }

    /**
     * 批量删除优惠券管理
     *
     * @param ids 需要删除的优惠券管理主键
     * @return 结果
     */
    @Override
    public int deleteCouponByIds(Long[] ids)
    {
        return couponMapper.deleteCouponByIds(ids);
    }

    /**
     * 删除优惠券管理信息
     *
     * @param id 优惠券管理主键
     * @return 结果
     */
    @Override
    public int deleteCouponById(Long id)
    {
        return couponMapper.deleteCouponById(id);
    }
}
